<?php

/**
 * 文章评论管理
 * @author tony<2014-11-15>
 */
class ArticleCommentAction extends CommonAction {

    /**
     * yl_cms_comment实例
     */
    private $_oModel = null;

    protected function _initialize() {
        parent::_initialize();
        $this->_oModel = M('cms_comments');
    }

    /**
     * 评论列表
     */
    public function lists() {
        import("ORG.Util.Page"); // 导入分页类
        //获取URL参数
        $map = array();
        $data = $_POST;
        $id = intval($data['id']);
        $userId = intval($data['user_id']);
        $articleId = intval($data['article_id']);
        $content = Common('Html')->text($data['content']);
        !empty($id) && $map['id'] = $id;
        !empty($userId) && $map['user_id'] = $userId;
        !empty($articleId) && $map['article_id'] = $articleId;
        !empty($content) && $map['content'] = array(
            'like',
            '%'.$content.'%'
        );

        $count = $this->_oModel->where($map)->count(); // 查询满足要求的总记录数
        $Page = new Page($count, 20); // 实例化分页类 传入总记录数和每页显示的记录数
        // 进行分页数据查询
        $lists = $this->_oModel->where($map)->order('id DESC')->limit($Page->firstRow . ',' . $Page->listRows)->select();
        $this->assign('page',$Page->show());
        $this->assign('lists', $lists);
        $this->display();
    }

    /**
     * 评论删除
     */
    public function delete() {
        $ids = $_POST['ids'];
        $map = array(
            'id'=>array(
                'in',$ids
            )
        );
        
        $result = $this->_oModel->where($map)->delete();
        if(!$result){
            echo 0;
            return;
        }
        echo 1;
    }

}
